<?php

namespace app\admin\controller;

use think\facade\Filesystem;

class File extends AdminBase {
    public function upload() {
        if (!$this->request->isPost()) {
            return show(config('status.error'), '请求不合法');
        }
        $file = $this->request->file('file');
//        dump($_FILES['file']['name']);
//        return;

        $filename = Filesystem::disk('public')->putFile('upload/file', $file);
        $filename = "/storage/" . $filename;
        if (!$filename) {
            return show(config('status.error'), '上传文件失败');
        }
        $result = [
            'code' => 0,
            'msg' => "success",
            'data' => [
                'name' => $_FILES['file']['name'],
                'src' => $filename
            ]
        ];
        return json($result);
    }
}